const express = require('express');

const app = express();


app.get('/home' ,(req, res) => {
    res.send('home');
});

//创建一个路由中间件
function checkCodeMiddleWare(req,res,next) {
    if (req.query.code === '521') {
        next();
    } else {
        res.send('暗号错误');
    }
}

app.get('/admin',checkCodeMiddleWare ,(req, res) => {
    res.send('admin');
});

app.get('/setting' ,checkCodeMiddleWare,(req, res) => {
    res.send('setting');
});
app.all('*' ,(req, res) => {
    res.send('<h1>404 Not Found</h1>');
});

app.listen(3000,() => {
    console.log('服务已启动 3000端口正在监听....');
});